import Vue from 'vue'
import Vuex from './vuex'
// import Vuex from 'vuex'

Vue.use(Vuex)
export default new Vuex.Store({
    //存储状态
    state: {
        num: 0
    },
    getters: {
        getNum(state) {
            return state.num
        }
    },
    mutations: {
        incre(state, payload) {
            state.num += payload
        },
        minus(state, payload) {
            state.num -= payload
        }
    },
    actions: {
        asyncIncre({ commit, dispatch }, payload) {
            //ajax
            setTimeout(() => {
                commit('incre', payload)
            }, 1000);
        }
    }
})